Skip to content

fix(macos): guard iOS-only methods in RCTViewComponentView.mm so the file compiles on macOS#2962

Open
tvinhas wants to merge 1 commit into
microsoft:0.83-mergefrom
tvinhas:fix-rctviewcomponentview-macos-compile
Open

fix(macos): guard iOS-only methods in RCTViewComponentView.mm so the file compiles on macOS#2962
tvinhas wants to merge 1 commit into
microsoft:0.83-mergefrom
tvinhas:fix-rctviewcomponentview-macos-compile

Conversation

@tvinhas

@tvinhas tvinhas commented May 13, 2026

Copy link
Copy Markdown

Summary

RCTViewComponentView.mm did not compile on macOS in 0.83-merge. The upstream 0.83 merge brought in new iOS-only methods that aren't wrapped in #if !TARGET_OS_OSX guards, leaving them visible to the macOS compile where they trip
duplicate-declaration errors against the existing AppKit-flavored methods in the macOS branch + use UIView / UIColor types unknown to AppKit.

Concrete errors blocking xcodebuild -scheme RNTester-macOS:

RCTViewComponentView.mm:810:3: error: unknown type name 'UIView'; did you mean 'NSView'?
RCTViewComponentView.mm:1048:4: error: expected a type (- (UIView )effectiveContentView)
RCTViewComponentView.mm:1371:11: error: unknown type name 'UIColor'; did you mean 'CIColor'?
RCTViewComponentView.mm:2412:43: error: expected a type (transferVisualPropertiesFromView:(UIView))
RCTViewComponentView.mm:2465:1: error: duplicate declaration of method 'handleCommand:args:'
RCTViewComponentView.mm:2478:1: error: duplicate declaration of method 'focus'
RCTViewComponentView.mm:2483:1: error: duplicate declaration of method 'blur'
RCTViewComponentView.mm:2490:1: error: duplicate declaration of method 'becomeFirstResponder'
RCTViewComponentView.mm:2503:1: error: duplicate declaration of method 'resignFirstResponder'

The macOS branch at lines 1846-2381 already provides AppKit-flavored versions of focus, blur, becomeFirstResponder, resignFirstResponder, handleCommand: — the duplicates after that block are iOS-canonical implementations
brought in by the upstream merge.

This PR is surgical: every change is either (a) wrapping iOS code in #if !TARGET_OS_OSX so it disappears from the macOS compile, or (b) swapping UIView* / UIColor* types for the existing fork-wide RCTPlatformView* /
RCTUIColor* compatibility aliases that resolve to the right AppKit class on macOS. No iOS behavior changes — every iOS code path executes identically before and after.

Changes (5 surgical edits)

  1. Line 810 — hitTest: local var. UIView *currentContainerViewRCTPlatformView *currentContainerView. The getter (currentContainerView declared at 1107) already returns RCTUIView* which is NSView* on macOS and UIView*
    on iOS; the local just needed to match.

  2. Lines 1048-1102 — effectiveContentView method. Return type UIView*RCTPlatformView*. Wrapped the SwiftUI-filter body in #if TARGET_OS_OSX ... return self; #else ... <existing body> ... #endif. The SwiftUI-filter wrapping
    uses RCTSwiftUIContainerViewWrapper which currently assumes UIKit's UIView surface — not yet ported to macOS. macOS falls back to the trivial return self path (callers continue to work because the type is RCTPlatformView*).

  3. Line 1109 — currentContainerView caller. UIView *effectiveContentView = self.effectiveContentView;RCTPlatformView *effectiveContentView = .... Matches the updated return type from change Update readme #2.

  4. Line 1371 — SwiftUI dropShadow color. UIColor *shadowColor = RCTUIColorFromSharedColor(...)RCTUIColor *shadowColor = .... RCTUIColor is the existing @compatibility_alias defined at
    React/RCTUIKit/RCTUIKitCompat.h:25-29 (UIColor on iOS, NSColor on macOS). RCTUIColorFromSharedColor already returns NSColor on macOS, and RCTSwiftUIContainerViewWrapper.h exposes the updateDropShadow:...color: selector with both
    UIColor (iOS) and NSColor (macOS) overloads — the typed alias picks the right one per platform.

  5. Lines 2412-2515 — wrap iOS-only methods in #if !TARGET_OS_OSX. Covers transferVisualPropertiesFromView:toView: (UIView-typed args), canBecomeFirstResponder (UIResponder semantics — macOS uses acceptsFirstResponder
    instead), and the duplicates of handleCommand:args: / focus / blur / becomeFirstResponder / resignFirstResponder that conflict with the AppKit-flavored versions in the macOS branch above.

Relationship to other in-flight PRs

Together, #2961 + this PR + #2959 are the minimum set required for xcodebuild -scheme RNTester-macOS build to succeed on 0.83-merge for Xcode 26.x. Without this PR, the file is rejected at the type-check stage and the whole
React-RCTFabric-macOS target fails to compile.

Closes the macOS-compile half of the "Verify focus changes" + "RNTester validation" items on the Road to 0.83 tracking issue (#2901). With #2960 (pbxproj restore) + this PR + #2961, xcodebuild ... -scheme RNTester-macOS build
now completes with ** BUILD SUCCEEDED **.

Test Plan

  • Before: xcodebuild -workspace packages/rn-tester/RNTesterPods.xcworkspace -scheme RNTester-macOS -configuration Debug -destination 'generic/platform=macOS' ARCHS=arm64 ONLY_ACTIVE_ARCH=YES CODE_SIGNING_ALLOWED=NO build fails at
    CompileC .../React-RCTFabric-macOS.build/.../RCTViewComponentView.o with the 9+ errors quoted above. Reproducible on a clean 0.83-merge checkout running Xcode 26.x.
  • After: same xcodebuild produces ** BUILD SUCCEEDED ** and a runnable Build/Products/Debug/RNTester-macOS.app. Validated locally with Xcode 26.5 / arm64 / Debug after applying both fix(fmt): patch base.h consteval gate via prepare_command for Xcode 26.x #2961 and this PR.
  • iOS regression check: every edit either swaps UIView/UIColor for RCTPlatformView/RCTUIColor (compat aliases that resolve identically to the original types on iOS) or moves iOS code inside #if !TARGET_OS_OSX. No iOS code
    path is removed; iOS RNTester build is unaffected.
  • 311 warnings remain after this PR — all pre-existing on 0.83-merge (deprecation notices on AppKit APIs, "build phase runs every build" hints, etc.), unrelated to this change.

Related

@tvinhas tvinhas requested a review from a team as a code owner May 13, 2026 20:24
@tvinhas tvinhas mentioned this pull request May 13, 2026
10 tasks
Comment on lines +1049 to +1059
// macOS: SwiftUI-filter wrapping isn't yet ported (the wrapper assumes
// UIKit's `UIView` / `RCTSwiftUIContainerViewWrapper` UIKit surface), so
// the macOS path short-circuits to `return self`. When the SwiftUI port
// lands for AppKit, gate the body on `enableSwiftUIBasedFilters()` &&
// !TARGET_OS_OSX. Return type is `RCTPlatformView*` so the macOS caller
// at currentContainerView compiles. [macOS]
- (RCTPlatformView *)effectiveContentView // [macOS]
{
#if TARGET_OS_OSX // [macOS
return self;
#else // macOS]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd want to fully implement the filters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants